//
//  Collection+Extension.swift
//  Test
//
//  Created by ZWJY on 2021/11/26.
//

import Foundation

// MARK: - 防止集合越界
public extension Collection {
    subscript (safe index: Self.Index) -> Iterator.Element? {
        (startIndex ..< endIndex).contains(index) ? self[index] : nil
    }
}


// MARK: - 字符串数组
public extension Collection where Element == String {

    /// 获取数组最大值
    func getMax() -> String {
        let a = self.max(by: {
            Double($0)! < Double($1)!
        })
        return a ?? ""
    }

    /// 获取数组最小值
    func getMin() -> String {
        let a = self.max(by: {
            Double($0)! > Double($1)!
        })
        return a ?? ""
    }
}
